﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DNMeter
{
    public partial class MainForm : Form
    {
		static Reccorder reccorder = null;
		static dom.Model testModel = null;

		private Reccorder GetReccorder() {
			if (reccorder == null)
			{
				reccorder = new Reccorder();
			}
			else {
				if (reccorder.IsDisposed) {
					reccorder = null;
					reccorder = new Reccorder();
				}
			}
			return reccorder;
		}

		private void LoadJMXFile() {
			if (this.openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
				String fileName = this.openFileDialog.FileName;
				testModel = new dom.Model(fileName, this.treeView );
			}
		}

        public MainForm()
        {
            InitializeComponent();
        }

		private void reccorderToolStripMenuItem_Click(object sender, EventArgs e)
		{
			int p = (int)System.Environment.OSVersion.Platform;
			if (p == 4 || p == 128)
			{
				MessageBox.Show("Sorry! Reccorder is **ONLY** supported in Windows!!" , this.Text );
			}
			else
			{
				MessageBox.Show("Windows Detected, Trying opening custom IE", this.Text); 
				GetReccorder().Show();
			}
		}

		private void openToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if ( testModel != null )
			{
				if ( MessageBox.Show ( "Replace Existing Project?" ,
				                      this.Text, MessageBoxButtons.YesNo ) 
				    == System.Windows.Forms.DialogResult.No ){
					return ;
				}  
			}
			LoadJMXFile();
		}
    }
}
